//
//  FunSelectController.m
//  diaoyuren
//
//  Created by 钓鱼人 on 16/3/21.
//  Copyright © 2016年 game. All rights reserved.
//

#import "FunSelectController.h"
#import "FunSelctTabView.h"
#import "PlusSignController.h"
#import "MJRefresh.h"
#import "LoginController.h"
@interface FunSelectController ()
@property (weak, nonatomic) IBOutlet UIView *Naview;
@property (weak, nonatomic) IBOutlet UIButton *bacBtn;
@property (weak, nonatomic) IBOutlet UISegmentedControl *navSelect;
@property (weak, nonatomic) IBOutlet UIButton *refresh;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *linght;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *navSelceWidth;
@property (weak, nonatomic) IBOutlet UIButton *issueBtn;
@property (nonatomic,strong) FunSelctTabView *allTableview;

@property (nonatomic,strong) FunSelctTabView *essenceTableview;

@end

@implementation FunSelectController

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.app.myTabBar.tabBar.hidden = YES;
    self.navigationController.navigationBar.hidden = YES;
    self.linght.constant = 0.5;
    StatusBlack;
}
- (IBAction)BackTo:(id)sender {
    
    self.essenceTableview.fatherCtrl = nil;
    self.allTableview.fatherCtrl = nil;
    self.essenceTableview = nil;
    self.allTableview = nil;
    [self.navigationController popViewControllerAnimated:YES];
}
#pragma mark---刷新Click
- (IBAction)refrshClick:(id)sender {

    switch (self.navSelect.selectedSegmentIndex) {
        case 0:
            [self.allTableview.header beginRefreshing];
            break;
            
        case 1:
            [self.essenceTableview.header beginRefreshing];
            break;

        default:
            break;
    }
}
#pragma mark--发帖点击
- (IBAction)IssueClick:(id)sender {
    if ([self.app.isLogin isEqualToString:@"YES"]) {
        PlusSignController *plus = [PlusSignController new];
        plus.fid = [NSString stringWithFormat:@"%ld",(long)self.fid];
        [self presentViewController:plus animated:YES completion:nil];
    }else{
    
        LoginController *login = [LoginController new];
        [self.navigationController pushViewController:login animated:YES];
    }
    
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    UIFont *font = [UIFont boldSystemFontOfSize:16.0f];
    NSDictionary *attributes = [NSDictionary dictionaryWithObject:font
                                                           forKey:UITextAttributeFont];
    [self.navSelect setTitleTextAttributes:attributes
                               forState:UIControlStateNormal];
    
[self.navSelect addTarget:self action:@selector(segmentAction:)forControlEvents:UIControlEventValueChanged];
    [self AddTableview];
 
    [self.view bringSubviewToFront:self.issueBtn];
    radius(self.issueBtn, 25);
    
    
    if (self.fid==37) {//前控制器是自拍 隐藏发帖按钮
        self.issueBtn.alpha = 0;
    }
}

-(void)AddTableview{
    
    self.essenceTableview = [[FunSelctTabView alloc]initWithFrame:CGRectMake(0, 64, screen_width, SCREEN_HEIGHT-64) style:UITableViewStylePlain];
    self.essenceTableview.fatherCtrl = self;
    self.essenceTableview.isEssence = @"YES";
    self.essenceTableview.fid = self.fid;
    [self.view addSubview:self.essenceTableview];
    
    
    self.allTableview = [[FunSelctTabView alloc]initWithFrame:CGRectMake(0, 64, screen_width, SCREEN_HEIGHT-64) style:UITableViewStylePlain];
    self.allTableview.fatherCtrl = self;
    self.allTableview.fid = self.fid;
    [self.view addSubview:self.allTableview];
}

-(void)segmentAction:(UISegmentedControl *)Seg{
    NSInteger Index = Seg.selectedSegmentIndex;
    
    switch (Index) {
            
        case 0:
            [self segmentAll];
            break;
            
        case 1:
            [self segmentEssence];
            break;
        
        default:
            
            break;
    }
}
#pragma mark--选择全部
-(void)segmentAll{
    self.allTableview.alpha = 1;
    self.essenceTableview.alpha = 0;
}
#pragma mark--选择精华
-(void)segmentEssence{
    self.allTableview.alpha = 0;
    self.essenceTableview.alpha = 1;
}
-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    
}


@end
